import 'package:flutter/material.dart';
import '../theme/SukietTheme.dart';


class SearchBox extends StatelessWidget {
  SearchBox({
    super.key,
    required this.focusNode,
    required this.controller,
    required this.onTextFieldSubmitted,
  }) {
    innerBorderRadius = SukietDarkTheme.defaultBorderRadius - innerPadding;
  }

  final double innerPadding = 6;
  final double outerHeight = 50;
  final FocusNode focusNode;
  final TextEditingController controller;
  final void Function() onTextFieldSubmitted;
  late final double innerBorderRadius;


  @override
  Widget build(BuildContext context) {
    return Container(
      height: outerHeight,
      decoration: SukietDarkTheme.cardDecorationWithoutShadow,
      child: Row(
        children: [
          Expanded(
            child: Padding(
              padding: EdgeInsets.all(innerPadding),
              child: Container(
                decoration: BoxDecoration(
                    color: Color.fromARGB(255, 39, 39, 39),
                    borderRadius: BorderRadius.circular(innerBorderRadius)),
                child: TextField(
                  onEditingComplete: () {
                    onTextFieldSubmitted();
                  },
                  controller: controller,
                  focusNode: focusNode,
                  cursorColor: Colors.white.withOpacity(0.86),
                  decoration: InputDecoration(
                    focusColor: Colors.white,
                    hintText: "Typing commands ...",
                    hintStyle: const TextStyle(
                        color: Color.fromARGB(255, 138, 138, 138)),
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(innerBorderRadius),
                    ),

                    /// only way to Vertically Center the content of TextField
                    contentPadding: const EdgeInsets.fromLTRB(16, 0, 0, 0),
                  ),
                  style: const TextStyle(
                    color: SukietDarkTheme.textColor,
                    fontSize: 14,
                  ),
                ),
              ),
            ),
          ),
          IconButton(
            onPressed: onTextFieldSubmitted,
            padding: EdgeInsets.zero,
            color: SukietDarkTheme.textColor,
            icon: const Icon(Icons.keyboard_return_sharp), // Icon(Icons.search)
          ),
          const SizedBox(
            width: 8,
          )
        ],
      ),
    );
  }
}